package com.acwing.partition12;

import java.io.*;
import java.util.PriorityQueue;

/**
 * @author `RKC`
 * @date 2022/1/8 15:39
 */
public class AC1127香甜的黄油dijkstra {

    private static final int N = 810, M = 1500 * 2, INF = 0x3f3f3f3f;
    private static int[] head = new int[N], element = new int[M], next = new int[M], weight = new int[M];
    //表示对应牧场有多少头牛
    private static int[] count = new int[N];
    private static int n = 0, p = 0, m = 0, index = 0;

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        String[] s = reader.readLine().split("\\s+");
        p = Integer.parseInt(s[0]);
        n = Integer.parseInt(s[1]);
        m = Integer.parseInt(s[2]);
        for (int i = 0; i < p; i++) count[Integer.parseInt(reader.readLine())]++;
        for (int i = 0; i < N; i++) head[i] = -1;
        for (int i = 0; i < m; i++) {
            s = reader.readLine().split("\\s+");
            int u = Integer.parseInt(s[0]), v = Integer.parseInt(s[1]), w = Integer.parseInt(s[2]);
            createEdge(u, v, w);
            createEdge(v, u, w);
        }
        int answer = INF;
        //从每个点出发找到其它所有点的最近距离和
        for (int i = 1; i <= n; i++) answer = Math.min(answer, dijkstra(i));
        writer.write(answer + "\n");
        writer.flush();
    }

    private static int dijkstra(int start) {
        int[] dist = new int[n + 1];
        for (int i = 1; i <= n; i++) dist[i] = INF;
        dist[start] = 0;
        PriorityQueue<int[]> heap = new PriorityQueue<>((o1, o2) -> Integer.compare(o1[1], o2[1]));
        heap.add(new int[]{start, 0});
        while (!heap.isEmpty()) {
            int[] curr = heap.poll();
            int u = curr[0];
            for (int i = head[u]; i != -1; i = next[i]) {
                int v = element[i];
                if (dist[v] > dist[u] + weight[i]) {
                    dist[v] = dist[u] + weight[i];
                    heap.add(new int[]{v, dist[v]});
                }
            }
        }
        //计算路径和
        int answer = 0;
        for (int i = 1; i <= n; i++) {
            if (dist[i] == INF && count[i] > 0) return INF;
            answer += count[i] * dist[i];
        }
        return answer;
    }

    private static void createEdge(int u, int v, int w) {
        element[index] = v;
        next[index] = head[u];
        head[u] = index;
        weight[index++] = w;
    }
}
